package com.hmall.trade.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.api.client.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.trade.domain.po.OrderDetail;
import com.hmall.trade.mapper.OrderDetailMapper;
import com.hmall.trade.service.IOrderDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 订单详情表 服务实现类
 * </p>
 *
 * @author 虎哥
 * @since 2023-05-05
 */
@Service
@RequiredArgsConstructor
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    private final IOrderDetailService detailService;
    private final ItemClient itemClient;

    @Override
    @Transactional
    public void restoreNum(Long orderId) {
        OrderDetail order = detailService.getById(orderId);
        int num = order.getNum();
        ItemDTO item = itemClient.queryItemById(orderId);
        int newNum = item.getStock() + num;
        item.setStock(newNum);
        itemClient.updateItem(item);

    }
}
